package com.knife.oauth.domain.service;

import com.knife.oauth.domain.entity.IamMemberRole;
import com.knife.oauth.domain.entity.IamUser;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;

/**
 * 构建 UserDetails
 *
 * @author： 76875
 * @date： 2022/4/13 星期三 10:55
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
public abstract class AbstractKnifeUserDetailsBuilder {

    /**
     * 构建 CustomUserDetails
     *
     * @param user     User
     * @param roleList 角色
     * @return CustomUserDetails
     */
    protected abstract UserDetails buildUserDetails(IamUser user, List<IamMemberRole> roleList);


    /**
     * 包装userDetails
     *
     * @param details userDetails
     */
    protected abstract void warp(UserDetails details);


    /**
     * 构建 CustomUserDetails
     *
     * @param user           User
     * @param memberRoleList 角色
     * @return CustomUserDetails
     */
    public UserDetails changeToUser(IamUser user, List<IamMemberRole> memberRoleList) {
        UserDetails userDetails = buildUserDetails(user, memberRoleList);

        warp(userDetails);

        return userDetails;
    }

}
